package 动态规划;

/**
 * @author tmh
 * @date 2024/12/16 21:30
 * @description
 */
public class T152乘积最大子数组 {
    public int maxProduct(int[] nums) {
        int result = Integer.MIN_VALUE;
        int imax = 1;
        int imin = 1;
        for (int i =0;i<nums.length;i++){
            if (nums[i]<0){
                //交换imax和imin的值
                int temp =imax;
                imax=imin;
                imin=temp;
            }
            imax=Math.max(nums[i],nums[i]*imax);
            imin=Math.min(nums[i],nums[i]*imin);
            result=Math.max(result,imax);
        }
        return result;
    }

}
